package com.admin.controller.base;

import com.github.pagehelper.PageInfo;
import com.admin.common.shiro.ShiroUtils;
import com.admin.domain.AdminDO;
import com.admin.vo.PageVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;

/**
 * 
 * @author ZY
 * @date 2018/10/18
 */
@CrossOrigin // 解决跨域
@Controller
public class BaseController {
    /**
     * 获取当前登录的用户信息
     * 
     * @return
     */
    public AdminDO getUser() {
        return ShiroUtils.getUser();
    }

    /**
     * 获取当前登录的用户id
     * 
     * @return
     */
    public Integer getUserId() {
        return getUser().getUserId();
    }

    /**
     * 获取当前登录的用户名
     * 
     * @return
     */
    public String getUsername() {
        return getUser().getUsername();
    }

    /**
     * 获取分页数据
     *
     * auther：zhangyang1
     * @param pageInfo
     * @return
     */
    protected <T> PageVO<T> pageResult(PageInfo<T> pageInfo) {
        PageVO<T> pageVO = new PageVO<T>();
        pageVO.setCurrentPage(pageInfo.getPageNum());
        pageVO.setPageSize(pageInfo.getPageSize());
        pageVO.setTotalCount((int) pageInfo.getTotal());
        pageVO.setData(pageInfo.getList());
        return pageVO;
    }
}